// components/data-select.js
const app = getApp();

Component({

  /**
   * 组件的属性列表
   */
  properties: {
    day: {
      type: String,
      value: ""
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    dataArr: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getData(){
      let today = new Date();
      let dataArr = [];
      for(var i = 0;i<7;i++){
        let obj = {
          week: '',
          dateLabel:'',
          dateValue: '',
        }
        let nextday = new Date(today.getTime() + 24 * 60 * 60 * 1000 * i);
        let nextyear = nextday.getFullYear();
        let month = (nextday.getMonth() + 1)<10?'0'+(nextday.getMonth() + 1):(nextday.getMonth() + 1);
        let day = nextday.getDate()<10?'0'+nextday.getDate():nextday.getDate();
          obj.dateLabel = month+"-"+day;
          obj.dateValue = nextyear+"-"+month+"-"+day;
          switch (nextday.getDay()) {
            case 1:
              obj.week= "周一";
              break;
            case 2:
              obj.week= "周二";
              break;
            case 3:
              obj.week= "周三";
              break;
            case 4:
              obj.week= "周四";
              break;
            case 5:
              obj.week= "周五";
              break;
            case 6:
              obj.week= "周六";
              break;
            case 0:
              obj.week= "周日";
              break;
          }
        
        dataArr.push(obj)
      }
      console.log(dataArr)

      this.setData({dataArr:dataArr})
     
    },

    changeDay(e) {
      this.setData({ day: this.data.dataArr[e.target.dataset.index].dateValue });
      this.triggerEvent('getDay',{day: this.data.dataArr[e.target.dataset.index].dateValue })
    }
  },
  ready: function () {
    this.getData()
  }
})